<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Acer
  Date: 2021/1/7
  Time: 15:11
  To change this template use File | Settings | File Templates.
--%>

<%--<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>--%>
<%--<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>--%>
<%--<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>--%>
<%--<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>--%>
<%--<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <%--    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">--%>
    <%--    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>--%>
    <%--    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>--%>
    <%--    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>--%>
    <%--    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>--%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/bootstrap/4.5.3/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath}/webjars/jquery/3.5.1/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/webjars/popper.js/1.16.0/popper.min.js"></script>
    <script src="${pageContext.request.contextPath}/webjars/bootstrap/4.5.3/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/webjars/vue/2.6.11/vue.min.js"></script>
    <title>list</title>
</head>
<body>




<div class="container">
    <div class="row">


        <div class="col-sm-8">
            <jsp:include page="head.jsp"></jsp:include>

            <h1>书籍列表</h1>
            <form class="form-inline" action="${pageContext.request.contextPath}/admin/book/list" method="get">
                <div class="input-group mb-1 w-50">
                    <input type="text" class="form-control w-auto" id="keyword" name="bn" placeholder="请输入书籍名称" value="${bn}">
                </div>
                <div class="input-group mb-1 w-25">
                    <input type="submit" class="form-control btn btn-primary ml-1" value="Search">
                </div>
                <div class="input-group mb-1">
                    <a href="${pageContext.request.contextPath}/admin/book/list" class="form-control btn btn-secondary ml-1">Clear</a>
                </div>

                <a href="${pageContext.request.contextPath}/admin/book/add" class="btn btn-primary ml-auto">add</a>
            </form>



            <table class="table table-sm table-hover table-light">
                <thead class="table-light">
                <tr>
                    <th>ID</th>
                    <th>BOOK_NAME</th>
                    <th>BOOK_PRICE</th>
                    <th>BOOK_STOCK</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="book" items="${books}">
                <tr>
                    <td>${book.isbn}</td>
                    <td>${book.bookName}</td>
                    <td>${book.price}</td>
                    <td>${book.stock}</td>
                    <td><a href="${pageContext.request.contextPath}/admin/book/update?isbn=${book.isbn}" class="text-primary">修改</a>&nbsp; | &nbsp;
                        <a href="${pageContext.request.contextPath}/admin/book/del?isbn=${book.isbn}" class="text-primary">删除</a></td>
                </tr>
                </c:forEach>
                </tbody>
            </table>

            <c:if test="${books.size()==0}">
                <div class="alert alert-info alert-dismissible">
                    <strong>提示!</strong> 未找到任何结果!
                    <button class="close" type="button" data-dismiss="alert">&divideontimes;</button>
                </div>
            </c:if>

        </div>

        <div class="col-sm-4"></div>
    </div>
</div>

<div class="container">
    <button class="btn btn-primary" onclick="getBooks()">getBooks</button>
    <p id="result"></p><p></p>
    <p><span id="bookId"></span><span id="bookName"></span></p>
</div>
<script type="text/javascript">
    <%--$(function () {--%>
    <%--    $.get("${pageContext.request.contextPath}/api/book/list", function (data) {--%>
    <%--        $("#bookId").text(data[0].bookId)--%>
    <%--        $("#bookName").text(data[0].bookName)--%>
    <%--        $("#bookId").text(JSON.stringify(data))--%>
    <%--    })--%>
    <%--})--%>

    function getBooks() {
        $.get("${pageContext.request.contextPath}/api/book/list", function (data) {
            $("#bookId").text(data[0].isbn)
            $("#bookName").text(data[0].bookName)
            $("#bookId").text(JSON.stringify(data))
        })
    }
</script>
























</body>
</html>
